package com.tul.exercise.base.operator.egs;


import org.junit.jupiter.api.Test;

import static com.tul.exercise.base.utils.Print.print;
/**
 * @Description 《java编程思想》第3章 示例6：
 *
 *  短路现象
 *
 **/
public class ShortCircuit {
    static boolean test1(int val) {
        print("test1(" + val + ")" + "result: " + (val < 1));
        //print("result: " + (val < 1));
        return val < 1;
    }

    static boolean test2(int val) {
        print("test2(" + val + ")" + ",result: " + (val < 2));
        //print("result: " + (val < 2));
        return val < 2;
    }

    static boolean test3(int val) {
        print("test3(" + val + ")" + ",result: " + (val < 3));
        //print("result: " + (val < 3));
        return val < 3;
    }

    @Test
    public void test() {

        // test2(2) 结果为false，test3()没有执行
        boolean b = test1(0) && test2(2) && test3(2);
        print("expression is " + b);

    }
}

